package com.wanshi.member.controller;


import com.wanshi.member.base.Result;
import com.wanshi.member.entity.Member;
import com.wanshi.member.req.MemberREQ;
import com.wanshi.member.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 会员信息表 前端控制器
 * </p>
 *删除
 * 添加
 * 修改
 * @author 顽石教育-www.wanshi.com
 * @since 2021-05-08
 */
@RestController
@RequestMapping("/member")
public class MemberController {


    @Autowired
    private IMemberService memberService;

    //    localhost:6666/member/list/search/1/20
    @PostMapping("/list/search/{page}/{size}")
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody MemberREQ req ) {
        return memberService.search(page, size, req);
    }


    /**
     * 新增会员
     * @param member
     * @return
     */
    @PostMapping // post /member
    public Result add(@RequestBody Member member) {
        boolean b = memberService.saveOrUpdate(member);
        if(b) {
            return Result.ok();
        }
        return Result.error("新增会员信息失败");
    }


    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") int id) {
        boolean b = memberService.removeById(id);
        if(b){
            return Result.ok();
        }
        return Result.error("删除会员信息失败");
    }

    @GetMapping("/{id}")
    public Result get(@PathVariable int id) {
        Member member = memberService.getById(id);
        return Result.ok(member);
    }

   /* @PutMapping("/{id}")
    public Result update(@PathVariable int id,
                         @RequestBody Member member) {
        return memberService.update(id, member);
    }*/

}
